package com.flykoc.lightinggem.command.subcommand;

import com.flykoc.lightinggem.dao.GemDao;
import com.flykoc.lightinggem.dto.LightingGem;
import com.flykoc.lightinggem.util.SubCommand;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

/**
 * 获取宝石指令
 *
 * @author Zoyn
 * @since 2017-10-21
 */
public class GetCommand implements SubCommand {

    @Override
    public void execute(CommandSender sender, String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage("§f你必须是一名玩家!");
            return;
        }

        Player player = (Player) sender;
        if (args.length != 2) {
            sender.sendMessage("§c参数不正确!");
            return;
        }
        String keyName = args[1];
        LightingGem gem = GemDao.getGem(keyName);
        if (gem == null) {
            sender.sendMessage("§c宝石不存在!");
            return;
        }
        player.getInventory().addItem(gem.getItemStack());
        sender.sendMessage("§a获取成功!");
        return;
    }
}
